class module:
	def __init__(self, parent):
		self.parent = parent

		self.events = ["onPrivmsg"]
		self.metadata = {
        "name":"Calculator",
        "description":"Calculator Module",
        "author":"Samuel Gordalina",
        "email":"samuel.gordalina@gmail.com",
        "version":"0.1",
        "required_version":(0,1)
		}
		
		self.namespace = {}
		exec "from math import *" in self.namespace, self.namespace	
	def test(self, code):
		return code
	def eval(self, code):
		try:
			return eval(code, self.namespace, self.namespace)
		except Exception ,message:
			return message


	def onPrivmsg(self, mask, message, channel=""):
		if channel == "":
			return

		command = message.split(" ")[0].lower()
		expression = message[len(command) +1:]

		if command == "!calc":
			result = self.eval(expression)
			self.parent.irc.privmsg(channel, expression + ' = ' + str(result))
